package cn.bonoon.core.info;

import java.util.HashMap;

import javax.servlet.http.HttpSession;

public class BnSessionContext {
	private static BnSessionContext instance;
	private HashMap map;

	private BnSessionContext() {
		map = new HashMap();
	}

	public static BnSessionContext getInstance() {
		if (null == instance) {
			synchronized (BnSessionContext.class) {
				if (null == instance) {
					instance = new BnSessionContext();
				}
			}
		}
		return instance;
	}

	public synchronized void AddSession(HttpSession session) {
		if (session != null) {
			map.put(session.getId(), session);
		}
	}

	public synchronized void DelSession(HttpSession session) {
		if (session != null) {
			map.remove(session.getId());
		}
	}

	public synchronized HttpSession getSession(String session_id) {
		if (session_id == null)
			return null;
		return (HttpSession) map.get(session_id);
	}
}
